package com.example.administrator.managesystem.fragment.myprofile.collect;

import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.ImageView;
import android.widget.Toast;

import com.example.administrator.managesystem.R;
import com.example.administrator.managesystem.activity.firstpage.wiki.WikiDetailActivity;
import com.example.administrator.managesystem.adapter.MyCollectWikiAdapter;
import com.example.administrator.managesystem.adapter.MyShareWikiAdapter;
import com.example.administrator.managesystem.adapter.WikiAdapter;
import com.example.administrator.managesystem.adapter.holder.MyCollectWikiHolder;
import com.example.administrator.managesystem.adapter.holder.MyShareWikiHolder;
import com.example.administrator.managesystem.adapter.holder.WikiHolder;
import com.example.administrator.managesystem.base.BaseFragment;
import com.example.administrator.managesystem.base.BaseHelper;
import com.example.administrator.managesystem.bean.CollectCircleBean;
import com.example.administrator.managesystem.bean.CollectWikiBean;
import com.example.administrator.managesystem.bean.WikiDetailBean;
import com.example.administrator.managesystem.bean.WikiListBean;
import com.example.administrator.managesystem.presenter.firstpage.FirstPagePresenter;
import com.example.administrator.managesystem.presenter.profile.MyCollectPresenter;
import com.example.administrator.managesystem.presenter.profile.MySharePresenter;
import com.example.administrator.managesystem.ui.MyCollectView;
import com.example.administrator.managesystem.ui.WikiView;
import com.example.administrator.managesystem.utils.ShareUtil;
import com.jcodecraeer.xrecyclerview.XRecyclerView;

import java.util.ArrayList;
import java.util.List;


public class MyCollectWikiFragment extends BaseFragment implements MyCollectView {
    // 定义
    private XRecyclerView mRecyclerView;
    private MyCollectWikiAdapter myXrecyclerAdapter;
    private MyCollectPresenter myCollectPresenter;
    private ArrayList<CollectWikiBean.DataBean> superList=new ArrayList<>();
    private int loadPage=1;
    @Override
    protected void initView(View view, Bundle savedInstanceState) {

        mRecyclerView=view.findViewById(R.id.recyclerview);

    }

    @Override
    protected int getLayoutId() {
        return R.layout.fragment_my_wiki;
    }

    @Override
    protected void doBusiness() {
        myCollectPresenter=new MyCollectPresenter(this);
        myCollectPresenter.wikiListRequest(ShareUtil.getUserId(getActivity()),ShareUtil.getUserToken(getActivity()),1,10,"a",0,getActivity());
        myXrecyclerAdapter=new MyCollectWikiAdapter(getActivity(),superList);
        BaseHelper.setLinearLayoutManagerVertical(getActivity(),mRecyclerView,myXrecyclerAdapter);
        myXrecyclerAdapter.addListener(new MyCollectWikiHolder.OnItemClickListener(){
            @Override
            public void onItemClick(int position, String wiki_id, View v) {
                myCollectPresenter.wikiDetailRequest(ShareUtil.getUserId(getActivity()),wiki_id,getActivity());
            }
        });

        mRecyclerView.setLoadingListener(new XRecyclerView.LoadingListener() {
            @Override
            public void onRefresh() {
                loadPage=1;
                myCollectPresenter.wikiListRequest(ShareUtil.getUserId(getActivity()),ShareUtil.getUserToken(getActivity()),1,20,"a",0,getActivity());
                mRecyclerView.refreshComplete();

            }

            @Override
            public void onLoadMore() {
                loadPage++;
                myCollectPresenter.wikiListRequest(ShareUtil.getUserId(getActivity()),ShareUtil.getUserToken(getActivity()),loadPage,20,"a",1,getActivity());
                mRecyclerView.loadMoreComplete();
            }
        });


    }

    @Override
    public void showCollectWikiList(List<CollectWikiBean.DataBean> list, int type) {

        Log.e("msg","list："+list);
        if(list.isEmpty()){
            return;
        }
        if(type==1){
            superList.addAll(list);
        }else{
            superList.clear();
            superList.addAll(list);
        }

        myXrecyclerAdapter.notifyDataSetChanged();
    }

    @Override
    public void showCollectCircleList(List<CollectCircleBean.DataBean> list, int type) {

    }

    @Override
    public void showWikiDetail(WikiDetailBean.DataBean dataBean) {
        Intent intent=new Intent(getActivity(),WikiDetailActivity.class);
        Bundle bundle = new Bundle();
        bundle.putSerializable("dataBean", dataBean);
        intent.putExtras(bundle);
        startActivity(intent);
    }

    @Override
    public void repost(String url, int type) {

    }

    @Override
    public void showSuccess(ImageView imageView) {

    }


}
